<?php
header('Content-Type:application/json;charset=UTF-8');
include("../../com/website_config.php");


$data=array();
$pro_tid=$_GET['type_id'];
//当前页码，page长度，star页码 end页码
$page=(int)$_GET['page'];
$pageL=(int)$_GET['pageL'];
$pageS=$pageL*($page-1);
$pageE=$page*$pageL;


switch($pro_tid){
//旅游租车，机场接送，企业班车
    case "navBus":
        $SQL="select * from ms_product where pro_tid>18 and pro_tid<57 order by pro_tid desc,pro_px desc";
        break;
//        丰田考斯特
    case "navCoaster":
        $pro_tid=array(18,20);
        $length=count($pro_tid);
    ////SELECT * FROM ms_product WHERE (pro_tid =18 OR pro_tid =20)ORDER BY pro_px DESC
        $str="";
        for ($i=0; $i<2; $i++){
            if($i==$length-1){
                $str.="pro_tid=".$pro_tid[$i];
                break;
            }
            $str.="pro_tid=".$pro_tid[$i]." OR ";
        }
        $SQL="select * from ms_product where ".$str." order by pro_tid desc,pro_px desc";
        break;
//        婚庆租车
    case "navMarry":
//    select * from car_nav group by car_brand order by if(car_brand REGEXP '奥迪|宝马|奔驰|保时捷|路虎' ,0,1),car_brand
//ORDER BY convert(car_brand using gbk) ASC
        $SQL="select * from car_nav group by car_brand order by if(car_brand REGEXP '奥迪|宝马|奔驰|保时捷|路虎' ,0,1),ORDER BY convert(car_brand using gbk) ASC";
        break;
//        商务会议
    case "navCar":
         $SQL="select * from ms_product where pro_tid=57 OR pro_tid=6 OR pro_tid=16 OR pro_tid=17 order by pro_tid desc,pro_px desc";
        break;
    case "all":
        $SQL="select * from ms_product order by pro_px desc";
        break;
    default:
        $SQL="select * from ms_product where pro_tid=$pro_tid order by pro_px desc";

}

$Record= $db->query($SQL);
//总记录数
$rc=mysql_num_rows($Record);

if($rc==""){
    echo"暂时还没有信息!";
}else{
     if($rc>$pageL){
        $sql=$SQL." LIMIT ".$pageS.",".$pageE;
     }else {
        $sql=$SQL;
     }
    $record = $db->query($sql);
    $i=0;
    while($array=mysql_fetch_array($record)){
        if($pro_tid==="navMarry"){
            $data[$i]= $array;
//            ../../uploads/1481765545_730827999.jpg
            $data[$i]["img"]=" ../../images/hc/".$array["car_img"];
            $data[$i]["pro_title"]="4+1座";

        }else{
            $pro_id=$array['pro_id'];
            $photoSQL="select * from ms_product_photo where pro_id=$pro_id limit 1";
            $rs=$db->query($photoSQL);
            $photoArray=mysql_fetch_array($rs);
            $pro_pic=$photoArray["img_path"];
            $data[$i]= $array;
            $data[$i]["img"]=$pro_pic;
        }
        $i++;

    }
}
$data["record"]=$rc;
echo json_encode($data);



?>